package com.zr.dao.impl;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.UserDao;
import com.zr.model.User;
import com.zr.util.JDBCUtil;

public class UserDaoImpl implements UserDao{

	@Override
	public User getUserDao(String uname, String upasw) {
		User user=new User();
	
		StringBuffer   sql = new StringBuffer();
		sql.append("SELECT e_user.uname,e_user.upsw ");
		sql.append("FROM  e_user ");
		sql.append("WHERE e_user.uname=? AND e_user.upsw=MD5(?) ");
		
		Connection  con =JDBCUtil.getConnection();
		try {
			PreparedStatement pst =con.prepareStatement(sql.toString());
			//指向的是方法里面的参数   把他的参数输入进去查找
			pst.setString(1, uname);
			pst.setString(2, upasw);
			//执行对象  pst 并把执行的结果返回给对象re
			ResultSet re=pst.executeQuery();
			if(re.next()){
				user.setUname(re.getString("uname"));
				user.setUpsw(re.getString("upsw"));	
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}	
		return user;
	}

}
